package day021.tcp.demo1;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TcpServer {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = new ServerSocket(9090);
        System.out.println("服务端程序已启动...");

        Socket server = ss.accept();
        System.out.println(server.getInetAddress().getHostAddress() + "客户端连接成功~");

        InputStream netInput = server.getInputStream();

        byte[] buf = new byte[1024];
        int len = netInput.read(buf);
        String msg = new String(buf, 0, len);

        System.out.println("客户端发送的数据：" + msg);
        netInput.close();
        server.close();
    }
}
